<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/25
 * Time: 10:56
 */

namespace app\zucai\home;
use app\index\controller\Home;
use think\Db;

/**
 * Class Content
 * @package app\zucai\home
 * 下单选项计算过关方式
 */
class Content extends Home
{
    public function two($date,$bei,$price){
        $cont=[];
        for($i=0;$i<count($date);$i++) {   //3场3串3
            for ($j = $i + 1; $j < count($date); $j++) {

                for ($k = 0; $k < count($date[$i]); $k++) {
                    for ($kv = 0; $kv < count($date[$j]); $kv++) {
                        $cont[] = round($date[$i][$k][1] * $date[$j][$kv][1] * $price * $bei,2);
                    }
                }
            }
        }
        return $cont;
    }
    public function tree($date,$bei,$price){
        $cont=[];
        for($i=0;$i<count($date);$i++) {  //4场4串4
            for ($j = $i + 1; $j < count($date); $j++) {
                for ($v = $j + 1; $v < count($date); $v++) {

                    for ($k = 0; $k < count($date[$i]); $k++) {
                        for ($kv = 0; $kv < count($date[$j]); $kv++) {
                            for ($kv2 = 0; $kv2 < count($date[$v]); $kv2++) {
                                $cont[] = round($date[$i][$k][1] * $date[$j][$kv][1]* $date[$v][$kv2][1] * $price * $bei,2);
                            }
                        }
                    }
                }
            }
        }
        return $cont;
    }
    public function four($date,$bei,$price){
        $cont=[];
        for($i=0;$i<count($date);$i++) {    //5串5   --4个一组
            for ($j = $i + 1; $j < count($date); $j++) {
                for ($v = $j + 1; $v < count($date); $v++) {
                    for ($v3 = $v + 1; $v3 < count($date); $v3++) {

                        for ($k = 0; $k < count($date[$i]); $k++) {
                            for ($kv = 0; $kv < count($date[$j]); $kv++) {
                                for ($kv2 = 0; $kv2 < count($date[$v]); $kv2++) {
                                    for ($kv3 = 0; $kv3 < count($date[$v3]); $kv3++) {
                                        $cont[] = round($date[$i][$k][1] * $date[$j][$kv][1] * $date[$v][$kv2][1]* $date[$v3][$kv3][1] * $price * $bei,2);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return $cont;
    }
    public function five($date,$bei,$price){
        $cont=[];
        for($i=0;$i<count($date);$i++) {    //6串6   --5个一组
            for ($j = $i + 1; $j < count($date); $j++) {
                for ($v = $j + 1; $v < count($date); $v++) {
                    for ($v3 = $v + 1; $v3 < count($date); $v3++) {
                        for ($v4 = $v3 + 1; $v4 < count($date); $v4++) {

                        for ($k = 0; $k < count($date[$i]); $k++) {
                            for ($kv = 0; $kv < count($date[$j]); $kv++) {
                                for ($kv2 = 0; $kv2 < count($date[$v]); $kv2++) {
                                    for ($kv3 = 0; $kv3 < count($date[$v3]); $kv3++) {
                                        for ($kv4 = 0; $kv4 < count($date[$v4]); $kv4++) {
                                            $cont[] = round($date[$i][$k][1] * $date[$j][$kv][1] * $date[$v][$kv2][1] * $date[$v3][$kv3][1]* $date[$v4][$kv4][1] * $price * $bei,2);
                                        }
                                    }
                                }
                            }
                        }
                        }
                    }
                }
            }
        }
        return $cont;
    }
    public function six($date,$bei,$price){
        $cont=[];
        for($i=0;$i<count($date);$i++) {    //7串7   --6个一组
            for ($j = $i + 1; $j < count($date); $j++) {
                for ($v = $j + 1; $v < count($date); $v++) {
                    for ($v3 = $v + 1; $v3 < count($date); $v3++) {
                        for ($v4 = $v3 + 1; $v4 < count($date); $v4++) {
                            for ($v5 = $v4 + 1; $v5 < count($date); $v5++) {

                            for ($k = 0; $k < count($date[$i]); $k++) {
                                for ($kv = 0; $kv < count($date[$j]); $kv++) {
                                    for ($kv2 = 0; $kv2 < count($date[$v]); $kv2++) {
                                        for ($kv3 = 0; $kv3 < count($date[$v3]); $kv3++) {
                                            for ($kv4 = 0; $kv4 < count($date[$v4]); $kv4++) {
                                                for ($kv5 = 0; $kv5 < count($date[$v5]); $kv5++) {
                                                $cont[] = round($date[$i][$k][1] * $date[$j][$kv][1] * $date[$v][$kv2][1] * $date[$v3][$kv3][1] * $date[$v4][$kv4][1]* $date[$v5][$kv5][1] * $price * $bei,2);
                                            }
                                        }
                                    }
                                }
                            }}
                            }
                        }
                    }
                }
            }
        }
        return $cont;
    }
    public function seven($date,$bei,$price){
        $cont=[];
        for($i=0;$i<count($date);$i++) {    //8串8   --7个一组
            for ($j = $i + 1; $j < count($date); $j++) {
                for ($v = $j + 1; $v < count($date); $v++) {
                    for ($v3 = $v + 1; $v3 < count($date); $v3++) {
                        for ($v4 = $v3 + 1; $v4 < count($date); $v4++) {
                            for ($v5 = $v4 + 1; $v5 < count($date); $v5++) {
                                for ($v6 = $v5 + 1; $v6 < count($date); $v6++) {

                                    for ($k = 0; $k < count($date[$i]); $k++) {
                                        for ($kv = 0; $kv < count($date[$j]); $kv++) {
                                            for ($kv2 = 0; $kv2 < count($date[$v]); $kv2++) {
                                                for ($kv3 = 0; $kv3 < count($date[$v3]); $kv3++) {
                                                    for ($kv4 = 0; $kv4 < count($date[$v4]); $kv4++) {
                                                        for ($kv5 = 0; $kv5 < count($date[$v5]); $kv5++) {
                                                            for ($kv6 = 0; $kv6 < count($date[$v6]); $kv6++) {
                                                                $cont[] = round($date[$i][$k][1] * $date[$j][$kv][1] * $date[$v][$kv2][1] * $date[$v3][$kv3][1] * $date[$v4][$kv4][1] * $date[$v5][$kv5][1]* $date[$v6][$kv6][1] * $price * $bei,2);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return $cont;
    }
    public function order(){
        if($this->request->isPost()){
            if($this->request->post()){
                $post=$this->request->post();
				
                if (!(isset($post['order']))) return returnError('未获取到订单选号');
                if (!(isset($post['play']))) return returnError('未获取到玩法选项');
                if (!(isset($post['beishu']))) return returnError('未获取到倍数');
                $price=Db::name('play_rule')->field('money')->where('id',1)->find();
                $price=$price['money'];
				
				
				$post['order']=explode('||',$post['order']);
		
               foreach ($post['order'] as $k=>$value){
                   $post['order'][$k]=explode(',',$value);
				  
                   foreach ($post['order'][$k] as $key=>$v){
                       $post['order'][$k][$key]=explode('@',$v);
                   }
               }
               $flag=count($post['order']);
               $date=$post['order'];
              $con=[]; $arr=[];$arr1=[];$arr2=[];$arr3=[];$arr4=[];$arr5=[];$arr6=[];

              if($flag==1){ //1场
                  for($i=0;$i<count($date[0]);$i++){
                      $con[]=round($date[0][$i][1]*$price*$post['beishu'],2);
                  }
              }elseif($flag==2){  //2场2串1
                   for($i=0;$i<count($date);$i++){
                       for($j=$i+1;$j<count($date);$j++){
                              for($k=0;$k<count($date[$i]);$k++){
                                      for($kv=0;$kv<count($date[$j]);$kv++){
                                          $con[]=round($date[$i][$k][1]*$date[$j][$kv][1]*$price*$post['beishu'],2);
                           }
                          }
                       }
                   }

               }elseif ($flag==3 ){ //3场
                                       for ($k = 0; $k < count($date[0]); $k++) {  //3场3串1
                                           for ($kv = 0; $kv < count($date[1]); $kv++) {
                                               for ($kv3 = 0; $kv3 < count($date[2]); $kv3++) {
                                                   $arr[] = round($date[0][$k][1] * $date[1][$kv][1]*$date[2][$kv3][1] * $price * $post['beishu'],2);
                                               }
                                           }
                                        }

                                       $arr1= $this->two($date,$post['beishu'],$price);

                   if($post['play']==1){   //3场3串1
                       $con=$arr;
                   }elseif ($post['play']==3){ //3场3串3
                       $con=$arr1;
                   }elseif($post['play']==4){ //3场3串4
                       $con=array_merge($arr,$arr1);
                   }

               }elseif($flag==4){ //4场

                       for ($k = 0; $k < count($date[0]); $k++) {  //4场4串1
                           for ($kv = 0; $kv < count($date[1]); $kv++) {
                               for ($kv3 = 0; $kv3 < count($date[2]); $kv3++) {
                                   for ($kv4 = 0; $kv4 < count($date[3]); $kv4++) {
                                       $arr[] =round($date[0][$k][1] * $date[1][$kv][1] * $date[2][$kv3][1]* $date[3][$kv4][1] * $price * $post['beishu'],2);
                                   }
                               }
                           }
                       }
                   $arr1= $this->tree($date,$post['beishu'],$price); //4场4串4
                   $arr2= $this->two($date,$post['beishu'],$price); //4场4串6

                   if($post['play']==1){   //4场4串1
                       $con=$arr;
                   }elseif ($post['play']==4) { //4场4串4
                       $con=$arr1;
                   }elseif($post['play']==6){ //4场4串6
                       $con=$arr2;
                   }elseif($post['play']==5){ //4场4串5
                       $con=array_merge($arr,$arr1);
                   }elseif($post['play']==11) { //4场4串11
                       $con = array_merge($arr, $arr1);
                       $con = array_merge($con, $arr2);
                   }
               }elseif($flag==5) { //5场

                       for ($k = 0; $k < count($date[0]); $k++) {         //5串1 --5个一组
                           for ($kv = 0; $kv < count($date[1]); $kv++) {
                               for ($kv3 = 0; $kv3 < count($date[2]); $kv3++) {
                                   for ($kv4 = 0; $kv4 < count($date[3]); $kv4++) {
                                       for ($kv5 = 0; $kv5 < count($date[4]); $kv5++) {
                                           $arr[] = round($date[0][$k][1] * $date[1][$kv][1] * $date[2][$kv3][1] * $date[3][$kv4][1] * $date[4][$kv5][1] * $price * $post['beishu'],2);
                                       }
                                   }
                               }
                           }
                       }
                   $arr1= $this->four($date,$post['beishu'],$price);//5串5  --4个1组
                   $arr2= $this->two($date,$post['beishu'],$price); //5串10  --2个1组
                   $arr3= $this->tree($date,$post['beishu'],$price); //5串16  --3个1组


                   if ($post['play'] == 1) {   //5场5串1
                       $con=$arr;
                   }elseif ($post['play'] == 5){//5场5串5
                       $con=$arr1;
                   }elseif ($post['play'] == 6) {  //5场5串6
                      $con=array_merge($arr,$arr1);
                   }elseif ($post['play'] == 10) {  //5场5串10
                      $con=$arr2;
                   }elseif ($post['play'] == 16) {  //5场5串16
                       $con=array_merge($arr,$arr1);
                       $con=array_merge($con,$arr3);
                   }elseif ($post['play'] == 20) {  //5场5串20
                       $con=array_merge($arr2,$arr3);
                   }elseif ($post['play'] == 26) {  //5场5串26
                       $con=array_merge($arr,$arr1);
                       $con=array_merge($con,$arr3);
                       $con=array_merge($con,$arr2);
                   }
               }elseif($flag==6) { //6场
                   for ($k = 0; $k < count($date[0]); $k++) {         //6串1 --6个一组
                       for ($kv = 0; $kv < count($date[1]); $kv++) {
                           for ($kv3 = 0; $kv3 < count($date[2]); $kv3++) {
                               for ($kv4 = 0; $kv4 < count($date[3]); $kv4++) {
                                   for ($kv5 = 0; $kv5 < count($date[4]); $kv5++) {
                                       for ($kv6 = 0; $kv6 < count($date[5]); $kv6++) {
                                           $arr[] = round($date[0][$k][1] * $date[1][$kv][1] * $date[2][$kv3][1] * $date[3][$kv4][1] * $date[4][$kv5][1]* $date[5][$kv6][1] * $price * $post['beishu'],2);
                                       }
                                   }
                               }
                           }
                       }
                   }

                   $arr1= $this->two($date,$post['beishu'],$price); //6串15  --2个1组
                   $arr2= $this->tree($date,$post['beishu'],$price); //6串20  --3个1组
                   $arr3= $this->four($date,$post['beishu'],$price); //      --4个1组
                   $arr4= $this->five($date,$post['beishu'],$price);//6串6  --5个1组

                   if ($post['play'] == 1) {   //6场6串1
                       $con=$arr;
                   }elseif ($post['play'] == 6){//6场6串6
                       $con=$arr4;
                   }elseif ($post['play'] == 7) {  //6场6串7
                       $con=array_merge($arr,$arr4);
                   }elseif ($post['play'] == 15) {  //6场6串15
                       $con=$arr1;
                   }elseif ($post['play'] == 20) {  //6场6串20
                       $con=$arr2;
                   }elseif ($post['play'] == 22) {  //6场6串22
                       $con=array_merge($arr,$arr4);
                       $con=array_merge($con,$arr3);
                   }elseif ($post['play'] == 35) {  //6场6串35
                       $con=array_merge($arr1,$arr2);
                   }elseif ($post['play'] == 42) {  //6场6串42
                       $con=array_merge($arr,$arr4);
                       $con=array_merge($con,$arr3);
                       $con=array_merge($con,$arr2);
                   }elseif ($post['play'] == 50) {  //6场6串50
                       $con=array_merge($arr1,$arr2);
                       $con=array_merge($con,$arr3);
                   }elseif ($post['play'] == 57) {  //6场6串57
                       $con=array_merge($arr,$arr4);
                       $con=array_merge($con,$arr3);
                       $con=array_merge($con,$arr2);
                       $con=array_merge($con,$arr1);
                   }

               }elseif($flag==7) { //7场
                   for ($k = 0; $k < count($date[0]); $k++) {         //7串1 --7个一组
                       for ($kv = 0; $kv < count($date[1]); $kv++) {
                           for ($kv3 = 0; $kv3 < count($date[2]); $kv3++) {
                               for ($kv4 = 0; $kv4 < count($date[3]); $kv4++) {
                                   for ($kv5 = 0; $kv5 < count($date[4]); $kv5++) {
                                       for ($kv6 = 0; $kv6 < count($date[5]); $kv6++) {
                                           for ($kv7 = 0; $kv7 < count($date[6]); $kv7++) {
                                               $arr[] = round($date[0][$k][1] * $date[1][$kv][1] * $date[2][$kv3][1] * $date[3][$kv4][1] * $date[4][$kv5][1] * $date[5][$kv6][1]* $date[6][$kv7][1] * $price * $post['beishu'],2);
                                           }
                                       }
                                   }
                               }
                           }
                       }
                   }

                   $arr1= $this->two($date,$post['beishu'],$price);  // --2个1组
                   $arr2= $this->tree($date,$post['beishu'],$price); //  --3个1组
                   $arr3= $this->four($date,$post['beishu'],$price); //  --4个1组
                   $arr4= $this->five($date,$post['beishu'],$price);//  --5个1组
                   $arr5= $this->six($date,$post['beishu'],$price);//  --6个1组

                   if ($post['play'] == 1) {   //7场7串1
                       $con=$arr;
                   }elseif ($post['play'] == 7){//7场7串7
                       $con=$arr5;
                   }elseif ($post['play'] == 8) {  //7场7串8
                       $con=array_merge($arr,$arr5);
                   }elseif ($post['play'] == 21) {  //7场7串21
                       $con=$arr4;
                   }elseif ($post['play'] == 35) {  //7场7串35
                       $con=$arr3;
                   }elseif ($post['play'] == 22) {  //7场7串22
                       $con=array_merge($arr,$arr4);
                       $con=array_merge($con,$arr3);
                   }elseif ($post['play'] == 35) {  //7场7串35
                       $con=array_merge($arr1,$arr2);
                   }elseif ($post['play'] == 120) {  //7场7串42
                       $con=array_merge($arr,$arr5);
                       $con=array_merge($con,$arr4);
                       $con=array_merge($con,$arr3);
                       $con=array_merge($con,$arr2);
                       $con=array_merge($con,$arr1);
                   }
               }elseif($flag==8) { //8场
                   for ($k = 0; $k < count($date[0]); $k++) {         //8串1 --8个一组
                       for ($kv = 0; $kv < count($date[1]); $kv++) {
                           for ($kv3 = 0; $kv3 < count($date[2]); $kv3++) {
                               for ($kv4 = 0; $kv4 < count($date[3]); $kv4++) {
                                   for ($kv5 = 0; $kv5 < count($date[4]); $kv5++) {
                                       for ($kv6 = 0; $kv6 < count($date[5]); $kv6++) {
                                           for ($kv7 = 0; $kv7 < count($date[6]); $kv7++) {
                                               for ($kv8 = 0; $kv8 < count($date[7]); $kv8++) {
                                                   $arr[] = round($date[0][$k][1] * $date[1][$kv][1] * $date[2][$kv3][1] * $date[3][$kv4][1] * $date[4][$kv5][1] * $date[5][$kv6][1] * $date[6][$kv7][1]* $date[7][$kv8][1] * $price * $post['beishu'],2);
                                               }
                                           }
                                       }
                                   }
                               }
                           }
                       }
                   }

                   $arr1= $this->two($date,$post['beishu'],$price);  // --2个1组
                   $arr2= $this->tree($date,$post['beishu'],$price); //  --3个1组
                   $arr3= $this->four($date,$post['beishu'],$price); //  --4个1组
                   $arr4= $this->five($date,$post['beishu'],$price);//  --5个1组
                   $arr5= $this->six($date,$post['beishu'],$price);//  --6个1组
                   $arr6= $this->seven($date,$post['beishu'],$price);//  --7个1组

                   if ($post['play'] == 1) {   //8场8串1
                       $con=$arr;
                   }elseif ($post['play'] == 8){//8场8串8
                       $con=$arr6;
                   }elseif ($post['play'] == 9) {  //8场8串9
                       $con=array_merge($arr,$arr6);
                   }elseif ($post['play'] == 28) {  //8场8串28
                       $con=$arr5;
                   }elseif ($post['play'] == 56) {  //8场8串56
                       $con=$arr4;
                   }elseif ($post['play'] == 70) {  //8场8串70
                       $con=$arr3;
                   }elseif ($post['play'] == 247) {  //8场8串247
                       $con=array_merge($arr,$arr6);
                       $con=array_merge($con,$arr5);
                       $con=array_merge($con,$arr4);
                       $con=array_merge($con,$arr3);
                       $con=array_merge($con,$arr2);
                       $con=array_merge($con,$arr1);
                   }
               }
               //排序计算最大值与最小值
                sort($con);
                $min=$con[0];
                rsort($con);
                $max=$con[0];
                $allmoney=$price*count($con)*$post['beishu'];
                return returnOk([$min,$max,$allmoney]);

            }else{
                return returnError('未获取到参数！');
            }
        }else{
            return returnError('请使用POST方式请求');
        }
    }
}